package lk.icta.core.entity;

import lk.icta.common.entity.BaseEntity;
import lk.icta.user.entity.User;

import javax.persistence.*;
import java.util.Date;

/**
 * @author Supun Viraj Rathnayaka
 */

@Entity
@Table(schema = "ELAND_RAIL")
@NamedQueries({
        @NamedQuery(
                name = "getPaymentByUserAndState",
                query = "SELECT l FROM Payment l WHERE l.paymentState =:state AND l.paymentType <> 3"
        ),
        @NamedQuery(
                name = "getAllPaymentByUserAndState",
                query = "SELECT l FROM Payment l WHERE l.paymentState =:state "
        ),
        @NamedQuery(
                name = "getSumOfAllPaymentsInAlienationSetInTimeFrame",
                query = "SELECT SUM(l.rentalAmount), SUM(l.taxAmount) FROM Payment l WHERE l.alienationId IN (:alienationIdSet) AND l.paymentDate BETWEEN :startDate AND :endDate"
        )
})

public class Payment extends BaseEntity {
    public enum PaymentType {
        CASH,       // 0
        CHEQUE,     // 1
        MONEY_ORDER, // 2
        UNIDENTIFIED // 3
    }

    public enum PaymentState {
        INVOICED, //
        CONFIRMED //
    }

    @Column(nullable = false)
    private int paymentType;

    @Column(nullable = false)
    private PaymentState paymentState;

    @Column(nullable = false)
    private String receiptReferenceNo;

    @Column(nullable = false)
    @Temporal(value = TemporalType.DATE)
    private java.util.Date billingDate;

    @Column(nullable = false)
    @Temporal(value = TemporalType.DATE)
    private java.util.Date paymentDate;

    @Column(nullable = true)
    private String description;

    @Column(nullable = false)
    private double rentalAmount;

    @Column(nullable = false)
    private double taxAmount;

    @Column(nullable = true)
    @Temporal(value = TemporalType.TIMESTAMP)
    private Date confirmedTimeStamp;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(nullable = true)
    private User confirmedUser;

    @Column(nullable = true)
    private long alienationId;

    @Embedded
    private LifeCycleInfo lifeCycleInfo = new LifeCycleInfo();

   /* @Column(nullable = false)
    @Temporal(value = TemporalType.TIMESTAMP)
    private Date invoicedTimeStamp;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(nullable = false)
    private User invoicedUser;
   */


    public int getPaymentType() {
        return paymentType;
    }

    public void setPaymentType(int paymentType) {
        this.paymentType = paymentType;
    }

    public PaymentState getPaymentState() {
        return paymentState;
    }

    public void setPaymentState(PaymentState paymentState) {
        this.paymentState = paymentState;
    }

    public String getReceiptReferenceNo() {
        return receiptReferenceNo;
    }

    public void setReceiptReferenceNo(String receiptReferenceNo) {
        this.receiptReferenceNo = receiptReferenceNo;
    }

    public Date getPaymentDate() {
        return paymentDate;
    }

    public void setPaymentDate(Date paymentDate) {
        this.paymentDate = paymentDate;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public double getRentalAmount() {
        return rentalAmount;
    }

    public void setRentalAmount(double rentalAmount) {
        this.rentalAmount = rentalAmount;
    }

    public double getTaxAmount() {
        return taxAmount;
    }

    public void setTaxAmount(double taxAmount) {
        this.taxAmount = taxAmount;
    }

    public Date getBillingDate() {
        return billingDate;
    }

    public void setBillingDate(Date billingDate) {
        this.billingDate = billingDate;
    }

    public LifeCycleInfo getLifeCycleInfo() {
        return lifeCycleInfo;
    }

    public void setLifeCycleInfo(LifeCycleInfo lifeCycleInfo) {
        this.lifeCycleInfo = lifeCycleInfo;
    }

    /*public Date getConfirmedTimeStamp() {
        return confirmedTimeStamp;
    }

    public void setConfirmedTimeStamp(Date confirmedTimeStamp) {
        this.confirmedTimeStamp = confirmedTimeStamp;
    }

    public User getConfirmedUser() {
        return confirmedUser;
    }

    public void setConfirmedUser(User confirmedUser) {
        this.confirmedUser = confirmedUser;
    }

    public Date getInvoicedTimeStamp() {
        return invoicedTimeStamp;
    }

    public void setInvoicedTimeStamp(Date invoicedTimeStamp) {
        this.invoicedTimeStamp = invoicedTimeStamp;
    }

    public User getInvoicedUser() {
        return invoicedUser;
    }

    public void setInvoicedUser(User invoicedUser) {
        this.invoicedUser = invoicedUser;
    }*/


    public Date getConfirmedTimeStamp() {
        return confirmedTimeStamp;
    }

    public void setConfirmedTimeStamp(Date confirmedTimeStamp) {
        this.confirmedTimeStamp = confirmedTimeStamp;
    }

    public User getConfirmedUser() {
        return confirmedUser;
    }

    public void setConfirmedUser(User confirmedUser) {
        this.confirmedUser = confirmedUser;
    }

    public long getAlienationId() {
        return alienationId;
    }

    public void setAlienationId(long alienationId) {
        this.alienationId = alienationId;
    }
}
